package org.ccheng.gui.info;

import de.felixroske.jfxsupport.FXMLController;
import io.reactivex.Observable;
import io.reactivex.internal.schedulers.NewThreadScheduler;
import io.reactivex.rxjavafx.observables.JavaFxObservable;
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.PublishSubject;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import org.ccheng.gui.console.ConsoleView;
import org.ccheng.gui.userInfo.UserInfoView;
import org.ccheng.xztx.service.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.net.URL;
import java.util.ResourceBundle;

@FXMLController
public class InfoCtrl implements Initializable {

    @FXML
    private BorderPane borderPane;
    @Autowired
    private UserInfoView userInfoView;
    @Autowired
    private ConsoleView consoleView;
    @Autowired
    private DailyService dailyService;
    @Autowired
    private SportService sportService;
    @Autowired
    private NewsService newsService;
    @Autowired
    private TianWuService tianWuService;
    @Autowired
    private ContestService contestService;
    @Autowired
    private DevilService devilService;
    @Autowired
    private WorldBossService worldBossService;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        borderPane.setCenter(consoleView.getView());
        borderPane.setRight(userInfoView.getView());

        borderPane.setBottom(getToolBar());
    }

    public Pane getToolBar() {
        GridPane pane = new GridPane();
        pane.setMinHeight(50);

        // 一键日常
        Button dailyBtn = new Button("一键领取日常奖励");
        dailyBtn.setMinHeight(50);
        JavaFxObservable.actionEventsOf(dailyBtn)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> dailyService.getAllTheRewards());
        pane.addColumn(0, dailyBtn);

        // 一键仙池
        Button sportButton = new Button("一键仙池");
        sportButton.setMinHeight(50);
        JavaFxObservable.actionEventsOf(sportButton)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> sportService.auto());
        pane.addColumn(1, sportButton);

        // 一键互动
        Button newsButton = new Button("一键互动");
        newsButton.setMinHeight(50);
        JavaFxObservable.actionEventsOf(newsButton)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> newsService.autoHelp());
        pane.addColumn(2, newsButton);

        // 一键天武
        Button tianWuButton = new Button("一键天武");
        tianWuButton.setMinHeight(50);
        JavaFxObservable.actionEventsOf(tianWuButton)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> tianWuService.auto());
        pane.addColumn(3, tianWuButton);

        // 一键天武
        Button contestBtn = new Button("一键斗法");
        contestBtn.setMinHeight(50);
        JavaFxObservable.actionEventsOf(contestBtn)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> contestService.auto());
        pane.addColumn(4, contestBtn);

        // 一键天武
        Button devilBtn = new Button("一键魔神塔");
        devilBtn.setMinHeight(50);
        JavaFxObservable.actionEventsOf(devilBtn)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> devilService.autoRandom());
        pane.addColumn(5, devilBtn);

        // 世界Boss
        Button worldBossBtn = new Button("世界Boss");
        worldBossBtn.setMinHeight(50);
        JavaFxObservable.actionEventsOf(worldBossBtn)
                .observeOn(Schedulers.io())
                .subscribe(actionEvent -> worldBossService.auto());
        pane.addColumn(6, worldBossBtn);

        return pane;
    }
}
